package com.jiangxjsy.admin.controller;

import cn.hutool.core.bean.BeanUtil;
import com.jiangxjsy.admin.service.AdminConfigService;
import com.jiangxjsy.core.wrap.Result;
import com.jiangxjsy.core.wrap.ResultBuilder;
import com.jiangxjsy.model.admin.bo.AdminCompanyBO;
import com.jiangxjsy.model.admin.entity.AdminConfig;
import com.jiangxjsy.model.admin.vo.ModuleSettingVO;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * wukong-crm-master
 * 蒋胜宇
 * 2025/6/6 16:28
 */

@RestController
@RequestMapping("/adminConfig")
public class AdminConfigController {
    @Resource
    private AdminConfigService adminConfigService;

    /**
     * 查询企业配置
     *
     * @return 企业配置
     */
    @PostMapping("/queryAdminConfig")
    public Result<AdminCompanyBO> queryAdminConfig() {
        return ResultBuilder.ok(adminConfigService.queryAdminConfig());
    }

    /**
     * 查询企业模块配置
     *
     * @return 模块配置
     */
    @PostMapping("/queryModuleSetting")
    public Result<List<ModuleSettingVO>> queryModuleSetting() {
        return ResultBuilder.ok(adminConfigService.queryModuleSetting());
    }

    /**
     * 查询头部模块排序
     *
     * @return 头部模块排序
     */
    @PostMapping("/queryHeaderModelSort")
    public Result<List<String>> queryHeaderModelSort(HttpServletRequest request, HttpServletResponse response) {
        return ResultBuilder.ok(adminConfigService.queryHeaderModelSort(request, response));
    }

    /**
     * 根据name查询配置
     *
     * @param name 配置名称
     * @return 配置
     */
    @RequestMapping("/queryFirstConfigByName")
    public Result<AdminConfig> queryFirstConfigByName(@RequestParam("name") String name) {
        AdminConfig config = adminConfigService.queryConfigByName(name);
        return ResultBuilder.ok(BeanUtil.copyProperties(config, AdminConfig.class));
    }
}
